#include <algorithm>
#include <iostream>
#include <vector>
#include <string.h>
#include <assert.h>
#include "BinFiles.h"

using namespace std;

int main()
{
	string filename = "Test.bin";
	const size_t filesize = 256;
	vector<char> buf(filesize, '\0'), buf2(filesize, '\0');

	// test case 1
	for (decltype(buf.size()) i = 0; i < buf.size(); i++)
	{
		buf[i] = (char)i;
	}

	SaveToFile(filename, buf);
	LoadFromFile(filename, buf2);

	for (decltype(buf2.size()) i = 0; i < buf2.size(); i++)
	{
		if (buf2[i] != (char)i)
		{
			cout << "Failed! (" << buf2[i] << ", ascii=" << i << ")" << endl;;
		}
	}

	// test case 2
	fill(buf.begin(), buf.end(), '\0');
	SaveToFile(filename, buf);
	LoadFromFile(filename, buf2);

	for (int i = 0; i < sizeof(buf2); i++)
	{
		buf[i] = (char)i;
		if (buf2[i] != (char)0)
		{
			cout << "Failed! (" << buf2[i] << ", ascii=" << i << ")" << endl;;
		}
	}

	// test case 3
	const int bin_size = 5;
	vector<vector<char>> binaries(5);
	vector<vector<char>> binaries2;

	for (decltype(buf.size()) i = 0; i < buf.size(); i++)
	{
		buf[i] = (char)i;
	}

	fill(binaries.begin(), binaries.end(), buf);
	SaveBinaries(binaries);

	LoadBinaries(binaries2);
	for (size_t i = 0; i < 5; ++i)
	{
		assert(binaries2.size() == binaries.size());

		for (size_t i2 = 0; i2 < binaries2[i].size(); i2++)
		{
			assert(binaries2[i][i2] == (char)i2);
		}
	}

	return 0;
}
